package com.fr.report.core.cal;

import com.fr.base.ArrayUtils;
import com.fr.base.ColumnRow;
import com.fr.report.CellElement;
import com.fr.report.FloatElement;
import com.fr.report.RWorkSheet;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.ScriptUtils;
import com.fr.report.js.CallBackable;
import com.fr.report.js.JavaScript;
import com.fr.report.js.NameJavaScript;
import com.fr.report.js.NameJavaScriptGroup;
import com.fr.report.parameter.Parameter;
import com.fr.report.script.Calculator;
import com.fr.report.script.CurrentValueNameSpace;
import com.fr.report.web.event.Listener;
import com.fr.report.web.ui.Widget;
import java.util.Iterator;

public final class SEAssist
{
  public static void preprocessorFloatElementHyperlink(RWorkSheet paramRWorkSheet, Calculator paramCalculator)
  {
    Iterator localIterator = paramRWorkSheet.floatIterator();
    while (localIterator.hasNext())
    {
      NameJavaScriptGroup localNameJavaScriptGroup;
      int i;
      FloatElement localFloatElement = (FloatElement)localIterator.next();
      CurrentValueNameSpace localCurrentValueNameSpace = new CurrentValueNameSpace(localFloatElement.getValue());
      paramCalculator.pushNameSpace(localCurrentValueNameSpace);
      if (localFloatElement.getNameHyperlinkGroup() != null)
      {
        localNameJavaScriptGroup = localFloatElement.getNameHyperlinkGroup();
        for (i = 0; i < localNameJavaScriptGroup.size(); ++i)
          calcultorJavaScriptParameter(localNameJavaScriptGroup.getNameHyperlink(i).getJavaScript(), paramCalculator, paramCalculator.getCurrentColumnRow());
      }
      paramCalculator.removeNameSpace(localCurrentValueNameSpace);
    }
  }

  public static void preprocessorJavaScriptParameter(CellElement paramCellElement, Calculator paramCalculator, boolean paramBoolean)
  {
    NameJavaScriptGroup localNameJavaScriptGroup;
    int j;
    int k;
    ColumnRow localColumnRow = ColumnRow.valueOf(paramCellElement.getColumn(), paramCellElement.getRow());
    paramCalculator.setCurrentColumnRow(localColumnRow);
    CurrentValueNameSpace localCurrentValueNameSpace = new CurrentValueNameSpace(paramCellElement.getValue());
    paramCalculator.pushNameSpace(localCurrentValueNameSpace);
    if (paramCellElement.getNameHyperlinkGroup() != null)
    {
      localNameJavaScriptGroup = paramCellElement.getNameHyperlinkGroup();
      for (j = 0; j < localNameJavaScriptGroup.size(); ++j)
        calcultorJavaScriptParameter(localNameJavaScriptGroup.getNameHyperlink(j).getJavaScript(), paramCalculator, localColumnRow);
    }
    if ((paramCellElement.getWidget() != null) && (((paramBoolean) || (!(paramCellElement.getWidget().isEditor())))) && (paramCellElement.getWidget().getListenerSize() > 0))
    {
      int i = paramCellElement.getWidget().getListenerSize();
      if (i > 0)
        try
        {
          paramCellElement.setWidget((Widget)paramCellElement.getWidget().clone());
        }
        catch (CloneNotSupportedException localCloneNotSupportedException)
        {
        }
      for (k = 0; k < i; ++k)
      {
        Listener localListener = paramCellElement.getWidget().getListener(k);
        calcultorJavaScriptParameter(localListener.getAction(), paramCalculator, localColumnRow);
      }
    }
    paramCalculator.removeNameSpace(localCurrentValueNameSpace);
  }

  private static void calcultorJavaScriptParameter(JavaScript paramJavaScript, Calculator paramCalculator, ColumnRow paramColumnRow)
  {
    int i;
    if (paramJavaScript == null)
      return;
    Parameter[] arrayOfParameter = paramJavaScript.getParameters();
    if (!(ArrayUtils.isEmpty(arrayOfParameter)))
      for (i = 0; i < arrayOfParameter.length; ++i)
      {
        Parameter localParameter = arrayOfParameter[i];
        Object localObject = localParameter.getValue();
        if (localObject instanceof Formula)
        {
          Formula localFormula = (Formula)localObject;
          localFormula.setResult(ScriptUtils.executeFormula(paramCalculator, localFormula, paramColumnRow));
        }
      }
    if (paramJavaScript instanceof CallBackable)
      calcultorJavaScriptParameter(((CallBackable)paramJavaScript).getCallBack(), paramCalculator, paramColumnRow);
  }
}